Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Orphaned encrypted_value when Credentials are deleted #728

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

hsinn0
Copy link
Contributor

@hsinn0 hsinn0 commented Apr 17, 2024

  • Fixed CredHub accumulates orphaned data in the the encrypted_value table #231 in JPA layer instead of using database triggers.
  • Used LAZY fetch for the JPA one-to-many mapping from credential to crdential_version because EAGER causes memory and perfromance issue when many credentials are loaded, e.g. DefaultCertificatesHandler.handleGetAllRequest(). The issue with EAGER fetch was reproducible in DefaultCertificatesHandlerIntegrationTest.
  • Made DefaultCertificatesHandlerIntegrationTest transactional so as not to commit test data. This not only makes sure no dirty test data is left but also makes the test runs a little faster.
  • Changed the credetial_version.type of test data in DefaultCertificatesHandlerIntegrationTest to a valid value 'cert' as previous invalid type value caused data vdalidation failure by Hibernate.
  • Changed properties of CredentialVersionData entity to be non-final, i.e. added Kotlin open keyword to them, so the lazy loading can work properly. This takes care of following exception for example:
WARN org.hibernate.tuple.entity.PojoEntityTuplizer - HHH000305: Could not create proxy factory for:org.cloudfoundry.credhub.entity.CredentialVersionData
  org.hibernate.HibernateException: Getter methods of lazy classes cannot be final: org.cloudfoundry.credhub.entity.CredentialVersionData#getUuid

[#187367323]

- Fixed #231 in JPA layer instead of using database triggers.
- Used `LAZY` fetch for the JPA one-to-many mapping from `credential` to `crdential_version` because `EAGER` causes memory and perfromance issue when many credentials are loaded, e.g. `DefaultCertificatesHandler.handleGetAllRequest()`. The issue with `EAGER` fetch was reproducible in `DefaultCertificatesHandlerIntegrationTest`.
- Made `DefaultCertificatesHandlerIntegrationTest` transactional so as not to commit test data. This not only makes sure no dirty test data is left but also makes the test runs a little faster.
- Changed the `credetial_version.type` of test data in `DefaultCertificatesHandlerIntegrationTest` to a valid value 'cert' as previous invalid type value caused data vdalidation failure by Hibernate.
- Changed properties of `CredentialVersionData` entity to be non-final, i.e. added Kotlin `open` keyword to them, so the lazy loading can work properly. This takes care of following exception for example:
```
WARN org.hibernate.tuple.entity.PojoEntityTuplizer - HHH000305: Could not create proxy factory for:org.cloudfoundry.credhub.entity.CredentialVersionData
  org.hibernate.HibernateException: Getter methods of lazy classes cannot be final: org.cloudfoundry.credhub.entity.CredentialVersionData#getUuid
```

[#187367323]
@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this. Unfortunately, the Pivotal Tracker project is private so you may be unable to view the contents of the story.

The labels on this github issue will be updated when the story is started.

@bruce-ricard bruce-ricard merged commit 34fd70c into main Apr 17, 2024
2 checks passed
@hsinn0 hsinn0 deleted the 187367323-lazy-fetch-one-to-many-mapping branch April 18, 2024 00:26
peterhaochen47 added a commit that referenced this pull request Jul 30, 2024
- issue: the "DROP TRIGGER" step of our MySQL DB migration fails
when used with AWS RDS MySQL 5.7 due to:
```
(conn=127) You do not have the SUPER privilege and binary logging is enabled
```
- We decided that the best approach is to just remove
this migration step, even though modifying past migrations is
not recommended by flyway (but in the past, in our context
removing migration steps have not created any problems).
- Note: This removal comes with a small problem where the triggers
in question are not removed (because we do want these triggers
to be removed, since they are not compatible with our latest code in
terms of DB cleanup, see: #728).
However, this problematic scenario should be quite narrow
(only for users who have successfully installed CredHub 2.12.67,
which adds the triggers, and have never upgraded to
any versions between 2.12.69 and the latest current version (2.12.84),
which contains the "DROP TRIGGER" step). For these users, we
will publish docs on how to fix it (manually drop the triggers).

[#187774971]
peterhaochen47 added a commit that referenced this pull request Aug 6, 2024
- issue: the "DROP TRIGGER" step of our MySQL DB migration fails
when used with AWS RDS MySQL 5.7 due to:
```
(conn=127) You do not have the SUPER privilege and binary logging is enabled
```
- We decided that the best approach is to just remove
this migration step, even though modifying past migrations is
not recommended by flyway (but in the past, in our context
removing migration steps have not created any problems).
- Note: This removal comes with a small problem where the triggers
in question are not removed (because we do want these triggers
to be removed, since they are not compatible with our latest code in
terms of DB cleanup, see: #728).
However, this problematic scenario should be quite narrow
(only for users who have successfully installed CredHub 2.12.67,
which adds the triggers, and have never upgraded to
any versions between 2.12.69 and the latest current version (2.12.84),
which contains the "DROP TRIGGER" step). For these users, we
will publish docs on how to fix it (manually drop the triggers).

[#187774971]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

CredHub accumulates orphaned data in the the encrypted_value table
3 participants